<template>
	<view class="container">
		<!-- 自定义导航栏 -->
		<view class="custom-nav-bar" :style="{ paddingTop: safeAreaInsets.top + 'px' }">
			<view class="nav-back" @click="navigateBack">
				<uni-icons type="back" size="24" color="#333"></uni-icons>
			</view>
			<text class="nav-title">消息通知</text>
		</view>

		<!-- 通知列表 -->
		<scroll-view class="notice-list" scroll-y>
			<view v-for="(item, index) in notifications" :key="index" class="notice-item"
				:class="{ unread: !item.isRead }" @click="markAsRead(index)">
				<uni-icons :type="item.icon" size="24" :color="item.color" class="notice-icon"></uni-icons>

				<view class="notice-content">
					<view class="notice-title">{{ item.title }}</view>
					<view class="notice-desc">{{ item.content }}</view>
					<view class="notice-time">{{ item.time }}</view>
				</view>

				<!-- 未读红点 -->
				<view v-if="!item.isRead" class="unread-badge"></view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				notifications: [{
						title: '版本更新通知',
						content: '当前有新版本可用，点击立即更新',
						time: '2025-04-20 09:30',
						icon: 'compose',
						color: '#007AFF',
						isRead: false
					},
					{
						title: '商品折扣提醒',
						content: '您关注的商品「新鲜牛排」已降价15%',
						time: '2025-04-19 16:45',
						icon: 'shop',
						color: '#DD524D',
						isRead: false
					},
					{
						title: '优惠活动通知',
						content: '周末大促：全场满300减50优惠进行中',
						time: '2025-04-18 11:20',
						icon: 'notification',
						color: '#4CD964',
						isRead: true
					},
					{
						title: '系统维护通知',
						content: '4月21日凌晨2:00-4:00系统维护',
						time: '2025-04-17 14:15',
						icon: 'settings',
						color: '#909399',
						isRead: false
					}
				],
				safeAreaInsets: {
					top: 0,
					bottom: 0
				}
			};
		},
		onLoad() {
			this.getSafeAreaInsets();
		},
		methods: {
			navigateBack() {
				uni.navigateBack();
			},
			markAsRead(index) {
				this.$set(this.notifications[index], 'isRead', true);
			},
			getSafeAreaInsets() {
				uni.getSystemInfo({
					success: (res) => {
						this.safeAreaInsets = {
							top: res.safeArea ? res.safeArea.top : res.statusBarHeight,
							bottom: res.safeArea ? res.safeArea.bottom : 0
						};
					},
					fail: (err) => {
						console.error('获取系统信息失败:', err);
					}
				});
			}
		}
	};
</script>

<style scoped>
	.container {
		height: 100vh;
		background-color: #f5f5f5;
	}

	/* 自定义导航栏 */
	.custom-nav-bar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0rpx 30rpx;
		background-color: white;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
		position: sticky;
		top: 0;
		height: 90rpx;
		z-index: 10;
	}

	.nav-back {
		display: flex;
		align-items: center;
	}

	.nav-title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		flex: 1;
		text-align: center;
	}

	.notice-list {
		height: calc(100vh - 90rpx);
		padding: 20rpx;
	}

	.notice-item {
		display: flex;
		align-items: center;
		padding: 20rpx;
		margin-bottom: 20rpx;
		background-color: #fff;
		border-radius: 16rpx;
		position: relative;
	}

	.notice-icon {
		margin-right: 20rpx;
	}

	.notice-content {
		flex: 1;
	}

	.notice-title {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
		margin-bottom: 10rpx;
	}

	.notice-desc {
		font-size: 28rpx;
		color: #666;
		margin-bottom: 10rpx;
	}

	.notice-time {
		font-size: 24rpx;
		color: #999;
	}

	.unread-badge {
		position: absolute;
		top: 20rpx;
		left: 20rpx;
		width: 16rpx;
		height: 16rpx;
		background-color: #DD524D;
		border-radius: 50%;
	}
</style>
